package com.yanqu.road.entity.config.system;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

/**
 * 项目权重
 */
public class NormalWeightItem {

	private BigInteger value = BigInteger.ZERO;

	private int weight;

	public BigInteger getValue() {
		return value;
	}

	public void setValue(BigInteger value) {
		this.value = value;
	}

	public int getWeight() {
		return weight;
	}

	public void setWeight(int weight) {
		this.weight = weight;
	}

	public NormalWeightItem() {

	}

	public NormalWeightItem(BigInteger value, int weight) {
		this.value = value;
		this.weight = weight;
	}

	public NormalWeightItem clone(){
		NormalWeightItem data = new NormalWeightItem();
		data.setValue(value);
		data.setWeight(weight);
		return data;
	}

	public static List<NormalWeightItem> parseWeightItemList(String weightParamStr){
		List<NormalWeightItem> dataList = new ArrayList<>();
		String[] valueArr = weightParamStr.split("\\|");
		for(String paramStr : valueArr) {
			String[] weightArr = paramStr.split(";");
			if(weightArr.length > 1) {
				NormalWeightItem weightItem = new NormalWeightItem();
				weightItem.setWeight(Integer.parseInt(weightArr[1]));
				weightItem.setValue(new BigInteger(weightArr[0]));
				dataList.add(weightItem);
			}
		}
		return dataList;
	}
}
